package main;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.io.BufferedReader;
import java.io.File;
import java.io.PrintWriter;
import java.net.Socket;

import javax.imageio.ImageIO;
import javax.swing.JDialog;
import javax.swing.JFrame;

/**
 * Klasa ramki logowania przeznaczona dla gracza
 * 
 * @author Maciej Krawczyk
 * @see javax.swing.JFrame
 */
@SuppressWarnings("serial")
public class GameFrame extends JFrame {

	/** Klasa z danymi potrzebnymi do sterowania GUI */
	private GuiData gd;
	/** Glowny panel gry */
	private GamePanel gp;
	/** Ramka gry */
	private GameFrame gf;
	/**
	 * modyfikator zarzadcy rozkladem
	 * 
	 * @see java.awt.GridBagConstraints
	 */
	private GridBagConstraints c;

	/**
	 * Konstruktor ramki gry
	 * 
	 * @param socket
	 *            gniazdko, na ktorym opiera sie komunikacja z serwerem
	 * @param out
	 *            Strumien wyjsciowy
	 * @param in
	 *            Strumien wejsciowy
	 */
	public GameFrame(Socket socket, PrintWriter out, BufferedReader in,
			InitiationFrame inf) {

		super("Badugi");
		gf = this;
		this.setLayout(new GridBagLayout());

		c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 0;
		c.fill = GridBagConstraints.BOTH;

		gp = new GamePanel(gf, inf);
		this.add(gp, c);
		gd = new GuiData(out, in, gp);
		gd.start();

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);

		try {
			setIconImage(ImageIO.read(new File("badugi_icon.png")));
		} catch (Exception e) {
			System.out.println("A");
		}

		setLocation(200, 10);
		JDialog.setDefaultLookAndFeelDecorated(true);

	}

	public void send(String message) {
		gd.send(message);
	}
}
